/*
 * Created on May 31, 2004
 *
 * Vectrics Inc.  GNU Public License.
 */
package org.vectrics.recruiter.user;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.vectrics.domain.Domain;
import org.vectrics.recruiter.document.CandidateDocument;
import org.vectrics.recruiter.document.CandidateDocumentCategory;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobApplication;
import org.vectrics.recruiter.job.JobCandidate;
import org.vectrics.recruiter.user.resume.email.EmailedResumeAttachment;
import org.vectrics.recruiter.user.resume.email.EmailedResumeCriteria;
import org.vectrics.recruiter.user.resume.email.EmailedResumeInfo;
import org.vectrics.user.Person;
import org.vectrics.user.PersonEncounterStatusType;
import org.vectrics.user.PersonMatchSet;
import org.vectrics.user.PersonNameList;
import org.vectrics.user.PersonService;

/**
 * @author mmoore
 */
public interface RecruitUserProvider extends PersonService {

	public static final String BEAN_ID = "recruit.user.service";	
	
	
	public Collection findInterviewResultTypesForStatus(PersonEncounterStatusType statusType);	
	public List findInterviewForJobCandidate(JobCandidate jobCandidate);	
	public Collection findResumesThatHaveExpired(Domain domain, int startIndex, int endIndex);
	public Collection findDocumentsForIndexing(Domain domain, int startIndex, int endIndex);
	public void writeDocumentToScanIndex(CandidateDocument document);
	public void wipeResumeIndex(Domain domain);
	
	public JobAgent findJobAgent(Long jobAgentId);
	public List findExpiredJobAgents(Domain domain, Date expirationTime, int maxCount);
	public List findJobsForJobAgent(JobAgent agent, int maxCount);
		
	public Resume findResume(Long resumeId);
	public void updateResume(Resume theResume);
	public void updateCandidateDocument(CandidateDocument document);
	
	public List findResumeIds(int maxDaysOld, Collection functionalAreas);
	//public Resume saveUserResumeText(CandidateInfo candidateInfo, String resumeText);
	public CandidateInfo findCandidateInfo(Person person);
	public CandidateInfo createCandidateInfoIfNotExist(Person person);

	public int findResumeScanResultsCount(Long batchNumber);
    public List findResumeScanResults(Long batchNumber, int start, int end);
    public void updateResumeScanBatch(ResumeScanBatch batch);
	public void removeResumeScanBatch(ResumeScanBatch batch);
    public ResumeScanBatch findResumeScanBatch(Long batchNumber);
    public void updateResumeScanResult(ResumeScanResult result);
	public void performResumeScan(ResumeScanBatch batch);
	public void clearResumeScanResults(ResumeScanBatch batch);
    public int findResumeScanBatchesCount(ResumeScanBatchCriteria criteria);
	public List findResumeScanBatches(ResumeScanBatchCriteria criteria, int start, int end);
	public void removeAllCriteria(ResumeScanBatch batch);
	
	public Interview createInterview(JobCandidate jobCandidate, Person leadPerson);
	public void removeJobAgents(CandidateInfo candidateInfo);
	public void updateCandidateInfo(CandidateInfo candidateInfo);
	public Interview findInterviewById(Long interviewId);
	public void updateInterview(Interview interview);
	public void removeInterview(Interview interview);
	public List findScheduledInterviews(Date startDate, Date endDate);
	public Collection findCandidateInterviews(CandidateInfo candidate);
	public int findInterviewCount(InterviewCriteria criteria);
	public List findInterviews(InterviewCriteria criteria, int startIndex, int endIndex);	
	
	public Collection getEmployments(Person person);
	public UserEmployment findEmployment(Person person, String empId);
	public UserEmployment createEmployment(Person person);
	public void removeEmployment(Person person);
	public Collection getEducations(Person person);
	public UserEducation findEducation(Person person);
	public UserEducation createEducation(Person person);
	public void removeEducation(Person person, String employmentId);
	
	public JobApplication findJobApplication(Long applicationId);
	public void updateJobApplication(JobApplication jobApplication);
	public void updateJobAgent(JobAgent jobAgent);
	public void updateJobAgentLocation(JobAgentLocation jobAgentLocation);
	public List findActiveCandidates(Domain domain, int startIndex, int endIndex);	
	public EmailedResumeAttachment findEmailedResumeAttachment(Long attachmentId);
	public void updateEmailedResume(EmailedResumeInfo emailedResumeInfo);
	public List findEmailedResumes(EmailedResumeCriteria criteria, int startIndex, int endIndex);
	public int findEmailedResumesCount(EmailedResumeCriteria criteria);
	public void updateEmailedResumeAttachment(EmailedResumeAttachment attachment);
	public EmailedResumeInfo findEmailedResume(Long id);
	public PersonMatchSet findPossibleCandidates(EmailedResumeInfo info);
	public List findAllCandidateDocumentCategories();
	public Set findJobAdminCompaniesForAuthPerson(Person authPerson);
	public CandidateDocumentCategory findCandidateDocumentCategory(String categoryCode);
	
	public void createCandidateDocumentForUserTextEntered(CandidateDocument textDocument, String resumeText);
	public void createCandidateDocument(CandidateDocument textDocument, String originalFileName, 
			InputStream contentStream);

	/**
	 * Save inputStream to local file system and point Resume object to this new file.
	 * @param candidate
	 * @param resume
	 * @param origFileName
	 * @param inputStream
	 */
	public void saveResumeToFile(CandidateInfo candidate, Resume resume, String origFileName, 
			InputStream inputStream);

	/**
	 * Save resume (passed as String) to local file system and point Resume object to this new file.
	 * @param candidate
	 * @param resume The persisted resume object
	 * @param origFileName The file name of the resume on the sender's machine.
	 * @param resumeText The full body of the resume to be stored.
	 */
	public void saveUploadedResumeToFile(CandidateInfo candidate, Resume resume, String resumeText);
	public CandidateDocument findCandidateDocument(Long documentId);
	public PersonMatchSet findPossibleCandidates(Domain domain, PersonNameList nameList, Set emails, Set phoneNumbers);

	public int findCandidateDocumentCount(Person person);
	public List findCandidateDocuments(Person person, int start, int end);

	public ResumeScanBatchJob findResumeScanBatchJob(Job job);
	public ResumeScanBatchJob createResumeScanBatchJob(Job job, ResumeScanBatch resumeScanBatch);
	
	public Resume findResume(CandidateDocument document);
	public InterviewResultType findInterviewResultType(String resultTypeCode);
	
	/**
	 * Metodo encargado de guardar el archivo y grabar en CandidateDocument
	 * @param person
	 * @param category
	 * @param originalFileName
	 * @param uploadStream
	 * @param name
	 */
	public void saveFile(Person person, String category,
			String originalFileName, InputStream uploadStream, String name );
	
	/**
	 * Elimina el documento de la base y el archivo fisico.
	 * @param document
	 */
	public void removeDocument(CandidateDocument document) throws IOException;
	
	/**
	 * Elimina el Resume de la base y no el archivo fisico.
	 * @param document
	 */
	public void removeResume(Resume resume);
	
}
